<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="用户名称">
              <a-select
                showSearch
                v-model="queryParam.violators"
                placeholder="请选择用户(可搜索)"
                @search="searchChange($event)"
                option-filter-prop="children"
                :filter-option="filterOption"
              >
                <a-select-option
                  :value="item.realname"
                  v-for="(item, index) in list"
                  :key="index"
                  >{{ item.realname }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="手机号">
              <a-select
                showSearch
                v-model="queryParam.phone"
                placeholder="请选择手机号(可搜索)"
                @search="searchChange($event)"
                option-filter-prop="children"
                :filter-option="filterOption"
              >
                <a-select-option
                  :value="item.phone"
                  v-for="(item, index) in phoneList"
                  :key="index"
                  >{{ item.phone }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="违规类型">
              <a-select
                showSearch
                v-model="queryParam.violationType"
                placeholder="请选择违规类型(可搜索)"
                @search="searchChange($event)"
                option-filter-prop="children"
                :filter-option="filterOption"
              >
                <a-select-option
                  :value="item"
                  v-for="(item, index) in violationList"
                  :key="index"
                  >{{ item }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" @click="queryTest(1)">文字内容违规</a-button>
      <a-button type="primary"  @click="queryTest(2)">音频内容违规</a-button>
    </div>
    
    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-wrap"
        @change="handleTableChange">

        <p class="contentSyl" slot="actions" slot-scope="text, record">
          <span v-if="record.type == 1">{{ record.violationContent }}</span>
          <img v-if="record.type == 2" style="width: 100px; height: 100px; borderRadiu:4px;" :src="record.violationContent" mode="aspectFit|aspectFill|widthFix" />
            
        </p>
        <span slot="action" slot-scope="text, record">
          <a @click="showDetails(record)">查看详情</a>
          <!-- <a-divider type="vertical" /> -->
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- modal -->
    <a-modal v-model="visible" title="详情" @ok="handleOk">
      <a-descriptions>
        <a-descriptions-item label="操作功能"  span="4">
          {{ details.operativeFunction }}
        </a-descriptions-item>
        <a-descriptions-item label="违规类型"  span="4">
          {{ details.violationType }}
        </a-descriptions-item>
        <a-descriptions-item label="操作时间"  span="4">
          {{ details.operateTime }}
        </a-descriptions-item>
        <a-descriptions-item label="违规内容"  span="6">
          <span v-if="details.type == 1">{{ details.violationContent }}</span>
          <img v-if="details.type == 2" style="width: 100px; height: 100px; borderRadiu:4px;" :src="details.violationContent" mode="aspectFit|aspectFill|widthFix" />
        </a-descriptions-item>
      </a-descriptions>
    </a-modal>

    <!-- 表单区域 -->
    <violationRecords-modal ref="modalForm" @ok="modalFormOk"></violationRecords-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import ViolationRecordsModal from './modules/ViolationRecordsModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { sysUserList, phoneListAPI, violationListAPI } from "@/api/tsapi";

  export default {
    name: "ViolationRecordsList",
    mixins:[JeecgListMixin],
    components: {
      ViolationRecordsModal
    },
    data () {
      return {
        description: '违规管理管理页面',
        visible: false,
        details:{},// 详情
        phoneList:[],// 手机号下拉列表
        violationList:[],// 违规类型下拉列表
        list:[],// 用户名称下拉列表
        // 表头
        columns: [
           {
            title: '违规人员',
            align:"center",
            dataIndex: 'violators'
           },
		   {
            title: '操作功能',
            align:"center",
            dataIndex: 'operativeFunction'
           },
		   {
            title: '违规类型',
            align:"center",
            dataIndex: 'violationType'
           },
		   {
            title: '违规内容',
            align:"center",
            // dataIndex: 'violationContent',
            dataIndex: 'violationContent',
            scopedSlots: {customRender: 'actions'},
           },
		   {
            title: '操作时间',
            align:"center",
            dataIndex: 'operateTime'
           },
           {
            title: '操作',
            dataIndex: 'action',
            scopedSlots: {customRender: 'action'},
            align: "center",
            width: 170
          }
        ],
      url: {
            list: "/violationRecords/violationRecords/list",
            delete: "/violationRecords/violationRecords/delete",
            deleteBatch: "/violationRecords/violationRecords/deleteBatch",
            exportXlsUrl: "violationRecords/violationRecords/exportXls",
            importExcelUrl: "violationRecords/violationRecords/importExcel",
        },
      }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  mounted() {
    console.log("this",this)
    this.userlist();
  },
    methods: {
      handleOk(){
        this.visible = false
      },
      showDetails(record){
        console.log("record",record)
        this.details = record
        this.visible = true
      },
      userlist(e) {
        let params = {
          realname: e,
        };
        sysUserList(params).then((res) => {
          if (res.code == 200) {
            this.list = res.result.records;
          }
        });
        phoneListAPI().then((res) => {
          console.log("手机列表",res)
          if(res.code == 200){
            this.phoneList = res.result.records
          }
        })
        violationListAPI().then((res) => {
          if(res.code == 200){
            this.violationList = res.result
          }
        })
        
        
      },
      queryTest(data) {
          this.queryParam.type = data
          this.searchQuery()
      },
      searchChange(e) {
        this.userlist(e);
      },
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text
            .toLowerCase()
            .indexOf(input.toLowerCase()) >= 0
        );
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .contentSyl{
    display: inline-block;
    width: 300px;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
</style>